# from rest_framework.decorators import action
#
# from dvadmin.system.models import AppUser, Users
# from dvadmin.utils.json_response import DetailResponse
# from dvadmin.utils.serializers import CustomModelSerializer
# from dvadmin.utils.viewset import CustomModelViewSet
# from dvadmin.utils.validator import CustomUniqueValidator
# from rest_framework import serializers
# from django.contrib.auth.hashers import make_password, check_password
#
#
#
# class AppUserSerializer(CustomModelSerializer):
#     """
#     app用户-序列化器
#     """
#
#     class Meta:
#         model = AppUser
#         fields = "__all__"
#         read_only_fields = ["id"]
#
#
# class AppUserCreateSerializer(CustomModelSerializer):
#     """
#     用户新增-序列化器
#     """
#
#
#
#     # username = serializers.CharField(
#     #     max_length=50,
#     #     validators=[
#     #         CustomUniqueValidator(queryset=Users.objects.all(), message="账号必须唯一")
#     #     ],
#     # )
#     # password = serializers.CharField(
#     #     required=False,
#     # )
#
#     # def validate_password(self, value):
#     #     """
#     #     对密码进行验证
#     #     """
#     #     password = self.initial_data.get("user_password")
#     #     if password:
#     #         return make_password(value)
#     #     return value
#
#     def save(self, **kwargs):
#         data = super().save(**kwargs)
#         # users = {
#         #     "username": self.data["login_name"],
#         #     "name": self.data["login_name"],  # 如果确实需要这样设置，则保留
#         #     "password": self.data["user_password"]
#         # }
#         # # super(users, self).save(*args, **kwargs)
#         # # Users.save(users)
#         # data = super().save(**kwargs)
#         # # data.dept_belong_id = data.dept_id
#         # data.save()
#         # data.post.set(self.initial_data.get("post", []))
#         return data
#
#     class Meta:
#         model = AppUser
#         fields = "__all__"
#         read_only_fields = ["id"]
#         extra_kwargs = {
#             "post": {"required": False},
#         }
#
#
# class AppUserCreateUpdateSerializer(CustomModelSerializer):
#     """
#     app用户管理 创建/更新时的列化器
#     """
#
#     def validate(self, attrs: dict):
#         return super().validate(attrs)
#
#     class Meta:
#         model = AppUser
#         fields = '__all__'
#
#
# class AppUserViewSet(CustomModelViewSet):
#     """
#     app用户管理接口
#     list:查询
#     create:新增
#     update:修改
#     retrieve:单例
#     destroy:删除
#     """
#     queryset = AppUser.objects.all()
#     serializer_class = AppUserSerializer
#     create_serializer_class = AppUserCreateSerializer
#
#
#     @action(methods=['GET'], detail=True)
#     def role_get_menu(self, request):
#         app_user_queryset = AppUser.objects.filter(users__id=request.user.id).values_list('data_range', flat=True)
#         return DetailResponse(data=app_user_queryset)
